/*******************************************************************************
03_05: Make Table X5: Effect of wife earning more than husband on each non-market
	work measure for women

Replication code for "Culture and gender allocation of tasks: source country 
	characteristics and the division of non-market work among US immigrants" in
	Review of Economics of the Household

Authors: Francine Blau, Lawrence Kahn, Matthew Comey, Amanda Eng, Pamela 
	Meyerhofer, and Alexander Willen
	
Date: 10/16/2020

*******************************************************************************/

/*******************************************************************************

I. Preliminaries

*******************************************************************************/

***A. Erase existing output if necessary
cap erase "$tables/Table_X5_Panel_A.xls"
cap erase "$tables/Table_X5_Panel_A.txt"
cap erase "$tables/Table_X5_Panel_B.xls"
cap erase "$tables/Table_X5_Panel_B.txt"
cap erase "$tables/Table_X5_Panel_C.xls"
cap erase "$tables/Table_X5_Panel_C.txt"
cap erase "$tables/Table_X5_Panel_D.xls"
cap erase "$tables/Table_X5_Panel_D.txt"


***B. Set control variables
local controls age age2 hsdi scol cold RACE2 RACE3 RACE4 RACE5 

local ch_controls young_children middle_children old_children

local part_controls part_age part_age2 part_hsdi part_scol part_cold part_RACE2 part_RACE3 part_RACE4 part_RACE5

local fe i.day i.month i.year i.statefip

local income_controls logearnings logearnings2 logearnings3 sp_logearnings sp_logearnings2 sp_logearnings3 fam_logearnings

local controls_im yrsusa1 yrsusa2 cohort70_79 cohort80_89 cohort90_99 cohort00_09 cohort10_17 

local part_controls_im part_immig part_secondgen part_yrsusa1 part_yrsusa2 part_cohort70_79 part_cohort80_89 part_cohort90_99 part_cohort00_09 part_cohort10_17

local source_country GDP fertility

local parent_source_country parent_GDP_000 parent_fertility


/*******************************************************************************

II. Run Regressions

*******************************************************************************/

local maintit  "Table X5: Effect of wife earning more than husband on non-market work for women"

**Loop through table panels
foreach panel in A B C D {
	
	*Set sample restrictions, controls, and labels
	preserve
	
	if "`panel'" == "A" {
		keep if female == 1
		
		local tabtit "`maintit', Panel A. All Women"
		
		local all_controls `controls' `part_controls' `ch_controls' `income_controls' `fe'
		
		local cluster ""
		}
		
	else if "`panel'" == "B" {
		keep if female == 1 & native_3rdp == 1
		
		local tabtit "`maintit', Panel B. Native Women"
		
		local all_controls `controls' `part_controls' `ch_controls' `income_controls' `fe'
		
		local cluster ""
		}
		
	else if "`panel'" == "C" {
		keep if female == 1 & immig == 1
		
		local tabtit "`maintit', Panel C. Immigrant Women"
		
		local all_controls `controls' `controls_im' `part_controls' `part_controls_im' `ch_controls' `income_controls' `fe'
		
		local cluster cluster(bpl)
		}
		
	else if "`panel'" == "D" {
		keep if female == 1 & secondgen == 1
		
		local tabtit "`maintit', Panel D. Second-Generation Women"
		
		local all_controls `controls' `part_controls' `part_controls_im' `ch_controls' `income_controls'   `fe'
		
		local cluster cluster(parent_bpl)
		}
		
		
	**Loop through non-market work variables
	foreach var in $nmw $hwork $ccare { 
		
		if "`var'" == "$nmw" {
			local coltit "Total Non-Market Work"
			}
		else if "`var'" == "$hwork" {
			local coltit "Housework"
			}
		else if "`var'" == "$ccare" {
			local coltit "Childcare"
			}
			
		*Main regression
		reg `var' wifeEarnsMore relinc `all_controls' [aw=newwt], robust `cluster'
		quietly sum `var' if e(sample)==1
		outreg2 using "$tables/Table_X5_Panel_`panel'.xls", keep(wifeEarnsMore) append addstat(Mean, r(mean)) label title("`tabtit'") ctitle(`coltit') nocons
		
		*For immigrants, add GGI and other source country controls
		if "`panel'" == "C" {
			
			reg `var' wifeEarnsMore relinc GGI `all_controls' `source_country' [aw=newwt], robust `cluster'
			quietly sum `var' if e(sample)==1
			outreg2 using "$tables/Table_X5_Panel_`panel'.xls", keep(wifeEarnsMore GGI) append addstat(Mean, r(mean)) label title("`tabtit'") ctitle(`coltit') nocons
			
			reg `var' wifeEarnsMore relinc GGI wifexGGI `all_controls' `source_country' [aw=newwt], robust `cluster'
			quietly sum `var' if e(sample)==1
			outreg2 using "$tables/Table_X5_Panel_`panel'.xls", keep(wifeEarnsMore GGI wifexGGI) append addstat(Mean, r(mean)) label title("`tabtit'") ctitle(`coltit') nocons
			
			}
			
		*For second-generation immigrants, add parent GGI and other source country controls
		if "`panel'" == "D" {
			
			reg `var' wifeEarnsMore relinc parent_GGI `all_controls' `parent_source_country' [aw=newwt], robust `cluster'
			quietly sum `var' if e(sample)==1
			outreg2 using "$tables/Table_X5_Panel_`panel'.xls", keep(wifeEarnsMore parent_GGI) append addstat(Mean, r(mean)) label title("`tabtit'") ctitle(`coltit') nocons
			
			reg `var' wifeEarnsMore relinc parent_GGI wifexparent_GGI `all_controls' `parent_source_country' [aw=newwt], robust `cluster'
			quietly sum `var' if e(sample)==1
			outreg2 using "$tables/Table_X5_Panel_`panel'.xls", keep(wifeEarnsMore parent_GGI wifexparent_GGI) append addstat(Mean, r(mean)) label title("`tabtit'") ctitle(`coltit') nocons
			
			}
			
		}
		
		
	restore
	
	}
	
	
***erase text files
cap erase "$tables/Table_X5_Panel_A.txt"
cap erase "$tables/Table_X5_Panel_B.txt"
cap erase "$tables/Table_X5_Panel_C.txt"
cap erase "$tables/Table_X5_Panel_D.txt"
